﻿using RN;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {        
        // Obtenemos el nombre de nuestros 
            string username = Request.QueryString["user"];
            UserId.Value = username;
            if(!IsPostBack){
                Session[Definitions.MAIL_CLIENT] = new MailClient(GlobalService.Server, username);
            }
    }

    protected void ToSend(object sender, EventArgs e)
    {
        Response.Redirect("Mail.aspx?Type="+Definitions.EMAIL_TYPE_SEND);    
    }

    [WebMethod(EnableSession = true)]
    public static List<JMessage> loadEmails(string username)
    {
        MailClient mailclient = (MailClient) HttpContext.Current.Session[Definitions.MAIL_CLIENT];
        List<Message> Messages = mailclient.ListMessages();
        List<JMessage> list = new List<JMessage>();
         foreach (Message m in Messages)
         {
             list.Add(GlobalService.ConvertMessageToJMessage(m));
         }
         return list;
    }
}